// .txt

beginzonescript;

variables;

short crime_tolerance = 5;
short last_abil;
short i;
short roamer_warn = 0;
short cutscene = 0;
short kludge_count = 0;

body;

beginstate INIT_STATE;

//	set_name(,"");
	add_range_to_group(13,20,1);
	add_range_to_group(21,26,2);

	add_range_to_group(28,35,3);
	
	set_obj_act_at_dist(26,1);
	set_obj_act_at_dist(27,1);
	set_obj_act_at_dist(140,1);
	
	set_level(37,3);
	
	set_name(38,"Crazed Roamer");
	set_aggression(38,7);
	change_max_health(38,120);
	
	add_range_to_group(51,58,4);
	set_level(1004,2);

	add_range_to_group(60,66,5);
	add_range_to_group(67,73,6);
	add_range_to_group(74,77,7);
	
	if (get_sdf(1,6) > 0) {
		make_zone_hostile();
		}

	sf(0,2,0);
	if (gf(0,1) > 0) {
		erase_char(8);
		erase_char(1001);
		erase_char(1002);
		erase_char(38);
		erase_char(1004);
		}
		else {
			sf(100,0,100);
			erase_char(1005);
			erase_char(1006);
			erase_char(1007);
			}
			
	last_abil = get_current_tick();
	
	set_crime_tolerance(crime_tolerance);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if ((get_flag(0,7) == 0) && (has_item_equip(61))) {
		set_flag(0,7,1);
		set_terrain_string_range("Now that you have a weapon, search the locker in the back of the storeroom. Click on a locker, box, or other container to open it.",3);
		}
	if ((get_flag(0,7) == 1) && (has_item(220))) {
		set_flag(0,7,2);
		set_terrain_string_range("When you get damaged in combat, you can use a healing pod to restore yourself. To use a healing pod, open the Inventory Window and press the starburst button by the pod.",3);
		}
		
	// clear zone?
	if ((zone_clear(ME) == FALSE) && (get_flag(0,25) > 0)) {
		print_str_color("Now that this door is open, you can pass this area freely.",2);
		clear_zone(ME);	
		}
		
	if ((get_crime_level() >= crime_tolerance) && (get_sdf(1,6) == 0)) {
		make_zone_hostile();
		set_flag(1,6,1);
		}
	if ((gf(1,6) > 0) && (gf(2,1) < 2)) 
		begin_talk_mode(290);
		
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(36,"Sss.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(36,"Sssss!");

//	last_abil = get_current_tick();

	if (
	((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_group()) && (tick_difference(last_abil,get_current_tick()) > 2))
	) {
		last_abil = get_current_tick();
		if ((gf(0,22) > 0) && (gf(0,22) < 100)) {
			inc_flag(0,22,1);
			spawn_creature(gf(0,22) + 32);
			set_level(gf(0,22) + 40,2);
			print_str_color("A big, slimy bug emerges from one of the vats.",2);
			if (gf(0,22) + 32 == 41)
				sf(0,22,100);
			}
		}
	
	// FINAL CUTSCENE
	if (gf(0,1) == 0) {
		if (((char_ok(50) == FALSE) || (get_health(50) < get_max_health(50) / 2)) && (party_near_nav(5,15))) {
			sf(0,1,1);
			
			if (cutscene == 0) {
				cutscene = 1;
				shift_view_to_char(pc_num());
				char_clear_action(1000);
				toggle_cutscene(1);
				}
			}
			
			
		}
	else if (cutscene == 1) {
		cutscene = 2;
		kludge_count = 0;
		begin_talk_mode(12);
		}
	else if (cutscene == 2) {
		move_to_loc(0,14,47);
		move_to_loc(1,15,46);
		move_to_loc(2,14,45);
		move_to_loc(3,16,45);
		move_to_loc(4,13,44);
		move_to_loc(5,15,44);
		move_to_loc(6,17,44);
		move_to_loc(7,15,43);

		move_to_loc(8,10,47);

		kludge_count = kludge_count + 1;
		
		if ((kludge_count >= 8) || (cutscene_can_proceed())) {
			kludge_count = 0;
			set_facing(1000,3);
			set_facing(8,3);
			shift_view_to_char(pc_num());
			cutscene = 3;
			}
		}
	else if (cutscene == 3) {
		cutscene = 4;
		}
	else if (cutscene == 4) {
		cutscene = 5;
		sf(0,28,1);
		spawn_creature(51);
		begin_talk_mode(13);
		}
	else if (cutscene == 5) {
		// kludgy emergency stuff. had errors where this scene broke, think is
		// fixed, but taking extra steps to keep it safe
		sf(0,28,1);
		if (char_ok(59) == FALSE)
			spawn_creature(51);
			
		cutscene = 6;
		}
	else if (cutscene == 6) {
		// kludgy emergency stuff
		sf(0,28,1);
		if (char_ok(59) == FALSE)
			spawn_creature(51);

		cutscene = 9;
		
		}
	else if (cutscene == 9) {
		move_to_loc(59,12,48);
		if ((char_ok(59) == FALSE) || ((dist_to_nav_point(59,5) <= 5) && (cutscene_can_proceed()))) {
			set_facing(59,7);
			shift_view_to_char(59);
			cutscene = 10;
			}
		
		}
	else if (cutscene == 10) {
		cutscene = 11;
		if ((cutscene == 11) && (char_ok(50) == FALSE) && (num_chars_in_group(4) == 0)) {
			cutscene = 16;
			}
		}
	else if (cutscene == 11) {
		cutscene = 12;
		begin_talk_mode(14);
		}
	else if (cutscene == 12) {
		give_char_text_bubble(59,"I absorb you!");
		run_a_char_animation(59,5,1,50);	
		run_sparkles_on_char(59,5,12,1);
		cutscene = 13;
		play_sound(238);
		}
	else if (cutscene == 13) {
		cutscene = 14;
		give_char_text_bubble(59,"I absorb you!");
		}
	else if (cutscene == 14) {
		give_char_text_bubble(59,"");
		kludge_count = kludge_count + 1;
		if ((kludge_count >= 6) || (cutscene_can_proceed())) {
			cutscene = 15;
			run_sparkles_on_char(1004,170,1,3);
			run_sparkles_on_char(50,170,1,3);
			damage_char(1004,1000 + get_ran(1,0,200),2);
			damage_char(50,1000 + get_ran(1,0,200),2);
			}
		}
	else if (cutscene == 15) {
		if ((kludge_count >= 6) || (cutscene_can_proceed())) 
			cutscene = 16;
		if ((cutscene == 16) && (num_chars_in_group(0) == 1)) {
			cutscene = 24;
			}
		}
	else if (cutscene == 16) {
		cutscene = 17;
		begin_talk_mode(15);
		}
	else if (cutscene == 17) {
		run_a_char_animation(59,5,1,50);	
		run_sparkles_on_char(59,5,12,1);
		play_sound(238);
		cutscene = 18;
		}
	else if (cutscene == 18) {
		cutscene = 19;
		}
	else if (cutscene == 19) {
		kludge_count = kludge_count + 1;
		if ((kludge_count >= 8) || (cutscene_can_proceed())) {
			cutscene = 20;
			i = 0; 
			while (i < 8) {
				if ((char_ok(i)) && (pc_num() != i)) {
					run_sparkles_on_char(i,170,1,3);
					damage_char(i,1000 + get_ran(1,0,200),2);
					}
				i = i + 1;
				}
			}
		}
	else if (cutscene == 20) {
		if ((kludge_count >= 8) || (cutscene_can_proceed()))
			cutscene = 24;
		}
	else if (cutscene == 24) {
		cutscene = 25;
		begin_talk_mode(16);
		}
	else if (cutscene == 25) {
		move_to_loc(8,12,59);
		kludge_count = kludge_count + 1;
		if ((kludge_count >= 8) || (cutscene_can_proceed())) {
			erase_char(8);
			cutscene = 26;
			}
		}
	else if (cutscene == 26) {
		cutscene = 27;
		}
	else if (cutscene == 27) {
		cutscene = 28;
		begin_talk_mode(170);
		}
	else if (cutscene == 28) {
		move_to_loc(59,12,59);
		give_char_text_bubble(59,"On to the next mess ...");
		if ((char_ok(59) == FALSE) || (dist_to_zone_loc(59,12,59) <= 1) || (cutscene_can_proceed())) {
			erase_char(59);
			cutscene = 29;
			}
		}
	else if (cutscene == 29) {
		cutscene = 30;
		toggle_cutscene(0);
		shift_view_to_char(pc_num());
		
		}
break;

beginstate 10;
	if (gf(0,1) == 0)
	set_terrain_string_range("Get comfortable with moving your character around. You can also select a character by drawing a box around it. Move the cursor onto the terrain, hold the mouse button down, and move the cursor to make the selection box.",7);
break;

beginstate 11;
	activate_hint(5);
break;

beginstate 12;
	if ((gf(0,7) > 0) && (gf(0,25) == 0)) {
		sf(0,25,1);
		give_object_message(26,103);
		give_object_message(27,103);
		}
	break;

beginstate 13;
	if (gf(0,11) == 0) {
		sf(0,11,1);
		if (gf(0,2) == 0) {
			sf(0,11,2);
			begin_talk_mode(57);
			}
			
		}
break;

beginstate 14;
	if (gf(0,14) == 0) {
		sf(0,14,1);
		if (gf(0,2) == 0) {
			sf(0,14,2);
			begin_talk_mode(86);
			}
			
		}
break;

beginstate 15;
	clear_hints();
	if (gf(0,15) == 0) {
		if ((num_chars_in_group(0) > 1) && (gf(0,2) > 0)) {
			sf(0,15,1);
			}
			else sf(0,15,2);
		}
break;

beginstate 16;
	if (gf(0,1) == 0) 
		set_terrain_string_range("This massive door blocks the way to the research warrens. It is sealed. You can't open it from this side.",3);
break;

beginstate 17;
	set_terrain_string_range("The sign says - RESEARCH WARREN CORE.",3);
break;

beginstate 18;
	activate_hint(11);
break;

beginstate 19;
	if ((gf(0,20) == 0) && (char_ok(38)) && (gf(0,1) == 0) && (gf(0,21) == 0)) {
		sf(0,20,1);
		begin_talk_mode(125);
		}
break;

beginstate 20;
	if ((char_ok(38)) && (roamer_warn == 0)) {
		roamer_warn = 1;
		begin_talk_mode(9);
		}
break;

beginstate 21;
	roamer_warn = 1;
break;

beginstate 22;
	if (gf(0,23) == 0) {
		sf(0,23,1);
		set_terrain_string_range("One useful tip: When you hold down the Tab key, you will see labels for all of the buttons (as well as other useful information). Try it out.",3);
		}
break;

beginstate 23;
	if ((char_ok(38)) && (get_attitude(38) < 10) && (gf(0,21) == 0)) {
		print_str_color("When you get close to the rogue roamer, it starts to notice you.",2);
		set_attitude(38,10);
		}
break;

beginstate 24;
	sf(1,21,1);
break;

//	print_str("");
//	set_terrain_string_range(".",3);
//	set_terrain_string_range("The sign says - .",3);
